\vsssub
\subsubsection{~Grids} \label{sec:grids}
\vsssub

% fig_grids_1

\input{sys/fig_grd1}

For convenience and economy of programming, spatial and spectral grids are
considered separately. This approach is inspired by the splitting technique
described in chapter~\ref{chapt:num}. For spatial propagation, a simple
`rectangular' spatial grid is used, as is illustrated in
Fig.~\ref{fig:grids_1}. The grid can either be a Cartesian `$(x,y)$' grid, a
spherical grid (with regular steps on latitude and longitude), a curvilinear
grid, or a triangle-based grid. In a spherical grid, the longitudes are
denoted throughout the program by the counter {\F ix}, and latitudes by the
counter {\F iy}, and the corresponding grid dimensions {\F (nx,ny)}. All
spatial field arrays are dynamically allocated within the code, corresponding
work arrays are usually automatic, to allow for thread-safe code. The closure
of the grid in case of a global applications is handled within the model, and
does not require user intervention. To simplify the calculation of derivatives
of in particular the current, the outer grid points ({\F ix=1,nx}, unless the
grid is global) and ({\F iy=1,ny}) will be considered as land points, inactive
points or active boundary points. The minimum grid size therefore is {\F nx=3,
  ny=3}, except for triangle-based grids. In that latter case, all the nodes
are listed as a long vector of dimension {\F nx}, while {\F ny=1}, allowing to keep the
same code structure. Input arrays are typically assumed to be of the form

\vspace{\baselineskip} \centerline{\F array(nx,ny) ,} \vspace{\baselineskip}

\noindent
and are read row by row (see also chapter~\ref{chapt:run}). Within the
program, however, they are typically stored with rotated indices

\vspace{\baselineskip} \centerline{\F array(ny,nx) .} \vspace{\baselineskip}

\noindent
This makes it easier to provide global closure, which typically requires
extension of the x axis. Furthermore, such two-dimensional array are usually
treated as one-dimensional arrays, to increase vector lengths. The array {\F
array}, its one-dimensional equivalent {\F varray} and {\F ixy} are defined as

\vspace{\baselineskip}
\centerline{\F array(my,mx) , varray(my*mx) ,}
\centerline{\F ixy = iy + (ix-1)*my .}
\vspace{\baselineskip}

\noindent
Note that this representation of the grid is used {\it internally} within the
model only.

% fig:grids_2

\input{sys/fig_grd2}

The spectral grid for a given spatial grid point {\F (ix,iy)} is defined
similarly, using a directional counter {\F ith} and a wavenumber counter {\F
ik} (Fig.~\ref{fig:grids_2}). The size of the spectral grid is set using
dynamic allocation. As with the spatial grid, the internal description of the
spectrum {\F a} is defined as

\vspace{\baselineskip}
\centerline{\F a(nth,nk) ,}
\vspace{\baselineskip}

\noindent
and equivalent one-dimensional arrays are used throughout the program. Inside
the model, directions are always Cartesian, $\theta = 0^\circ$ corresponds to
propagation from west to east (positive $x$ or {\F ix} direction), and $\theta
= 90^\circ$ corresponds to propagation from south to north (positive $y$ or
{\F iy} direction). Output directions use other conventions, as is discussed
in Chapter~\ref{chapt:run}.

The storage of the wave spectra accounts for the majority of the memory
required by the model, because the splitting technique used assures that any
part of the model operates on a small subset of the entire wave field. To
minimize the amount of memory needed, only spectra for actual sea points are
stored. Sea points are here defined as points where spectra are potentially
needed. This includes active boundary points, and sea points covered by
ice. For archiving purposes, a one-dimensional sea point grid is defined using
the counter {\F isea}. Spectra are then stored as

\vspace{\baselineskip}
\centerline{\F a(ith,ik,isea) .}
\vspace{\baselineskip}

\noindent
An example of the layout of this storage grid in relation to the full grid of
Fig.~\ref{fig:grids_1} is given in Fig.~\ref{fig:grids_3}. Obviously, the
relation between the storage grid and the full spatial grid requires some
bookkeeping. For this purpose, two `maps' {\F mapfs} and {\F mapsf} are
defined.

\vspace{\baselineskip}
\centerline{\F mapsf(isea,1) = ix ,}
\centerline{\F mapsf(isea,2) = iy ,}
\centerline{\F mapsf(isea,3) = ixy ,}
\centerline{\F mapfs(iy,ix) = vmapfs(ixy) = isea ,}
\vspace{\baselineskip}

% fig:grids_3

\input{sys/fig_grd3}

\noindent
where {\F mapfs(iy,ix) = 0} for land points. Finally, status maps {\F
mapsta(iy,ix)} and {\F mapst2(iy,ix)} are maintained to identify sea, land,
active boundary and ice points. {\F mapsta} represents the main status
map for the grid;

\vspace{\baselineskip} \noindent
\strut \hspace{25mm} {\F mapsta(iy,ix) = 0} \hspace{10mm} for excluded points, \\
\strut \hspace{25mm} {\F mapsta(iy,ix) = 1} \hspace{10mm} for sea points, \\
\strut \hspace{25mm} {\F mapsta(iy,ix) = 2} \hspace{10mm} for active boundary points.

\vspace{\baselineskip}

Sea points and active boundary point which are not considered in the wave
model due to the presence of ice are marked by their corresponding negative
status indicator (-1 or -2). {\F mapst2} contains secondary information. For
excluded points {\F mapsta(iy,ix) = 0}, this map distinguished between land
points {\F mapst2(iy,ix) = 0} and otherwise excluded points {\F mapst2(iy,ix)
= 1}. For sea points that are disabled {\F mapsta(iy,ix) < 0}, consecutive
bits in {\F mapst2} identify the reason for deactivation (bit value 1
indicating deactivation).

\begin{center} \begin{tabular}{cl}
 bit & identifies \\ \hline
  1  & Ice coverage     \\
  2  & Point dried out  \\
  3  & Land in moving grid or inferred in nesting \\
  4  & Masked in two-way nesting
\end{tabular} \end{center}


Two additional considerations have been made. First, the two status maps can
be collapsed into a single map for storage. To assure that the storage is
backward compatible with the previous mode version, the two maps are combined
into a single map {\F maptmp}

\vspace{\baselineskip}
\centerline{\F maptmp = mapsta + 8 * mapst2}
\vspace{\baselineskip}

\noindent
considering that only the first few bits of {\F mapsta} contain data.
It is this map MAPTMP that is saved in NetCDF files.  The
original maps can be recovered as

\vspace{\baselineskip}
\centerline{\F mapsta = mod ( maptmp + 2 , 8 ) - 2}
\centerline{\F mapst2 = maptmp - mapsta}
\vspace{\baselineskip}

\noindent
Second, a single map is used in the graphics output program, to simplify the
plotting of the status of grid points. In the graphics files, the map is
defined as

\begin{center} \begin{tabular}{cl}
{map} & implies \\ \hline
  2 & Active boundary point \\
  1 & Active sea point      \\
  0 & Land point (including as identified in {\F MAPST2} \\
 -1 & Point covered by ice, but wet \\
 -2 & Dry point, not covered by ice \\
 -3 & Dry point covered by ice \\
 -4 & Point masked in the two-way nesting scheme \\
 -5 & Other disabled point
\end{tabular} \end{center}

\noindent
Similarly, a single map can be used to simplify processing in the grid
preparation program {\file ww3\_grid}. In this map a distinction is made
between points as follows:

\begin{center} \begin{tabular}{cl}
{map} & implies \\ \hline
  3 & Excluded points \\
  2 & Active boundary point \\
  1 & Active sea point      \\
  0 & Land point 
\end{tabular} \end{center}
